﻿function PopUp(dialogId, overlayId, contentId) {

    this.id = "#" + dialogId;
    this.overlayId = "#" + overlayId;
    this.contentId = "#" + contentId;

    this.ShowDialog = function ShowDialog(modal) {

        $(this.overlayId).show();
        $(this.id).fadeIn(300);

        if (modal) {
            $(this.overlayId).unbind("click");
        }
        else {
            $(this.overlayId).click(function (e) {
                HideDialogWin();
            });
        }
    }

    this.ShowDialogWithContent = function ShowDialogWithContent(modal, content) {

        $(this.overlayId).show();
        $(this.id).fadeIn(300);
        $(this.contentId).val(content);

        //console.warn(content);

        if (modal) {
            $(this.overlayId).unbind("click");
        }
        else {
            $(this.overlayId).click(function (e) {
                HideDialogWin();
            });
        }
    }

    this.CloseDialog = function HideDialogWin() {

        $(this.overlayId).hide();
        $(this.id).fadeOut(300);
    }

    this.ClosePopUp = function ClosePopUp() {

        $(this).find("input[type=text], input[type=password]").each(function () {
            $(this).val("");
            $(this).removeClass("input-validation-error");
        });

        $(this).find("span.field-validation-error").each(function () {

            $(this).removeClass("field-validation-error").addClass("field-validation-valid");
        });

        this.CloseDialog();
    }
}